package com.hotdog.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 时间自动赋值工具类
 *
 * @author 郭鲁政
 */
@Component
public class MyMetaObjectHandLer implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("createtime", date, metaObject);
        this.setFieldValByName("uploaddata", date, metaObject);
        this.setFieldValByName("watchTime", date, metaObject);


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("createtime", new Date(), metaObject);
        this.setFieldValByName("uploaddata", new Date(), metaObject);
        this.setFieldValByName("watchTime", new Date(), metaObject);

    }
}
